package io.renren.modules.workpos.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.workpos.entity.WorkposEntity;
import io.renren.modules.workpos.service.WorkposService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

@RestController
@RequestMapping("workpos/workpos")
public class WorkposController {
    @Autowired
    private WorkposService workposService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("workpos:workpos:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = workposService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{workNo}")
    @RequiresPermissions("workpos:workpos:info")
    public R info(@PathVariable("workNo") Integer workNo){
		WorkposEntity workpos = workposService.getById(workNo);

        return R.ok().put("workpos", workpos);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("workpos:workpos:save")
    public R save(@RequestBody WorkposEntity workpos){
		workposService.save(workpos);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("workpos:workpos:update")
    public R update(@RequestBody WorkposEntity workpos){
		workposService.updateById(workpos);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("workpos:workpos:delete")
    public R delete(@RequestBody Integer[] workNos){
		workposService.removeByIds(Arrays.asList(workNos));

        return R.ok();
    }

}
